import React, { Component } from 'react'
import axios from "axios" // axios 是ajax的一个类库 ajax xmlhttprequest
class Login extends Component {
   state = {
       val:""
   }
   changeVal(e){
       console.log(e.target.value)
       this.setState({
           val:e.target.value
       })
   }
   sendFn(){
        axios.get("/login1",{params:{
            user:this.state.val}
        }).then(res=>{
            console.log(res.data)
            if (res.data.code == 1) {
                // 本地存储只能存字符串
                window.localStorage.setItem("isLogin","true")
            }else {
                window.localStorage.setItem("isLogin","false")
            }
        })
   }
  render() {
    return (
      <div>
         用户名： <input type="text" value={this.state.val} onChange={this.changeVal.bind(this)}/>
         <button onClick={this.sendFn.bind(this)}>登陆</button>
      </div>
    )
  }
}

export default Login